//
//  UIColor+Extension.h
//  UIColor分类
//
//  Created by 申岳 on 16/8/4.
//  Copyright © 2016年 shenyue. All rights reserved.
//

#import <UIKit/UIKit.h>
//颜色创建
#undef  RGBCOLOR
#define RGBCOLOR(r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]

#undef  RGBACOLOR
#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]

#undef	HEX_RGB
#define HEX_RGB(V)		[UIColor colorWithRGBHex:V]

#define MIN3(x,y,z)  ((y) <= (z) ? \
((x) <= (y) ? (x) : (y)) \
: \
((x) <= (z) ? (x) : (z)))

#define MAX3(x,y,z)  ((y) >= (z) ? \
((x) >= (y) ? (x) : (y)) \
: \
((x) >= (z) ? (x) : (z)))


struct rgb_color {
    CGFloat r, g, b;
};

struct hsv_color {
    CGFloat hue;
    CGFloat sat;
    CGFloat val;
};

@interface UIColor (Extension)
@property (nonatomic, readonly) CGFloat hue; // Only valid if canProvideRGBComponents is YES
@property (nonatomic, readonly) CGFloat saturation; // Only valid if canProvideRGBComponents is YES
@property (nonatomic, readonly) CGFloat brightness; // Only valid if canProvideRGBComponents is YES
@property (nonatomic, readonly) CGFloat value; // (same as brightness, added for naming consistency)



//返回颜色的空间模式
@property (nonatomic, readonly) CGColorSpaceModel colorSpaceModel;
//获取y颜色的空间必须为kCGColorSpaceModelRGB，kCGColorSpaceModelMonochrome
@property (nonatomic, readonly) BOOL canProvideRGBComponents;
//取出颜色的r值
@property (nonatomic, readonly) CGFloat red;
//取出颜色的g值
@property (nonatomic, readonly) CGFloat green;
//取出颜色的b值
@property (nonatomic, readonly) CGFloat blue;
//取出颜色的white值
@property (nonatomic, readonly) CGFloat white;
//取出颜色的a值
@property (nonatomic, readonly) CGFloat alpha;
//取出颜色的rgbHex值
@property (nonatomic, readonly) UInt32 rgbHex;
/**
 *  根据十六进制格式来设置颜色
 */
+ (UIColor *)colorWithRGBHex:(UInt32)hex;
/**
 *  根据字符串的十六进制格式转换可以用在plist中读到来设置
 */
+ (UIColor *)colorWithHexString:(NSString *)stringToConvert;
/**
 *  根据一种颜色的计算出  @"{0.300, 0.400, 0.500, 1.000}"
 */
- (NSString *)stringFromColor;
/**
 *  返回有个十六进制的4D6680颜色值
 */
- (NSString *)hexStringFromColor;
/**
 * 随机颜色
 */
+ (UIColor *)randomColor;
/**
 * 把颜色rgba的值放在一个数组
 */
- (NSArray *)arrayFromRGBAComponents;
/**
 * 根据css中的颜色来设置cssColorName是颜色的名字
 */
+ (UIColor *)colorWithName:(NSString *)cssColorName;
/**
 *  
 */
- (UIColor *)colorByLuminanceMapping;

/*****hsv****/
+(struct hsv_color)HSVfromRGB:(struct rgb_color)rgb;
//individual value accessors:
-(CGFloat)hue;
-(CGFloat)saturation;
-(CGFloat)brightness;
-(CGFloat)value;



@end
